package cn.yanxiaohui.service.web.config;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;

import cn.yanxiaohui.service.web.marco.BookMarkDetailMarco;
import freemarker.template.Configuration;
import freemarker.template.TemplateModelException;

/**
 * freemarker的自定义配置，可在此处加入宏
 * @author yanxh
 *
 */
@org.springframework.context.annotation.Configuration
public class FreemarkerConfig {

	@Autowired
	private Configuration configuration;
	
	@Autowired
	private BookMarkDetailMarco bookMarkDetailMarco;
	
	
	@PostConstruct
	public void setSharedVariable() throws TemplateModelException {
		configuration.setSharedVaribles(getSharedVaribles());
		configuration.setClassicCompatible(true); // 处理页面空值
	}
	
	/**
	 * 宏的map
	 * @return
	 */
	public Map<String, Object> getSharedVaribles() {
		Map<String, Object> sharedVaribles = new HashMap<String, Object>();
		sharedVaribles.put("_bookMarkList", bookMarkDetailMarco);
		return sharedVaribles;
	}

}